<template>
	<view class="header-bg-image header-bg">
		<view style="height: 50rpx;"></view>
		<view class="padding-30">
			<view class="margin-30-0 flex-around" @click="$tools.switchTab('/pages/mine/mine')">
				<u-icon name="arrow-left" color="#333333" size="20"></u-icon>
				<view class="fontSize-18 color-000 flex1 text-center">我的课程</view>
				<view style="width: 40rpx;"></view>
			</view>
			<view class="margin-30-0">
				<u-tabs :list="list1" lineColor="#967C5E" @click="chooseTabs"></u-tabs>
			</view>
			<!-- 课程列表 -->
			<view class="class-item" @click="$tools.navigateTo('/pages/mine/mine-list/my-class-info?id='+item.id)"
			v-for="(item,index) in list" :key="index">
				<image class="img-160 margin-right20 border-radius10" :src="item.goods2.image" mode=""></image>
				<view class="flex1">
					<view class="margin-bottom20 fontSize-14 color-704234">{{item.goods2.title}}</view>
					<view class="flex-flex-warp" v-if="item.goods2.tag">
						<view class="goods-info-tag flex-center" v-for="(item1,index1) in item.goods2.tag.split(',')" :key="index1">{{item1}}</view>
					</view>
					<!-- <view class="flex-alignItems-center margin-bottom20">
						<u-icon name="clock" color="#704234" size="20"></u-icon>
						<view class="margin-left20 color-704234 fontSize-13">{{item.createtime}}</view>
					</view> -->
				<!-- 	<view class="flex-alignItems-center">
						<u-icon name="map" color="#704234" size="20"></u-icon>
						<view class="margin-left20 color-704234 fontSize-15">西悦城22楼</view>
					</view> -->
				</view>
				<view class="flex-justAliCenter-column">
					<view class="color-FE3232 margin-bottom30">
						<text class="fontSize-13 margin-right10">￥</text>
						<text class="fontSize-18 fontWeight-bold">{{item.goods2.price}}</text>
					</view>
					<view class="writeOff flex-center" v-if="item.course_count !== 0">核销</view>
				</view>
			</view>
			<u-empty v-if="list.length == 0" mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png"
				width="150px" height="150px" text="列表为空" textSize="18">
			</u-empty>
			<view style="padding-bottom: 100rpx;">
				<u-loadmore v-if="loading" status="loading" />
				<u-loadmore v-if="isLastPage" status="nomore" />
			</view>
		</view>
	</view>
</template>

<script>
	import goodsItem from "@/components/goods/goods.vue"
	export default {
		components: {
			goodsItem
		},
		data() {
			return {
				// tabs列表
				list1: [{
					name: '全部',
					status: 0
				}, {
					name: '学习中',
					status: 1
				}, {
					name: '已完结',
					status: 2
				}],
				status: 0,
				page: 1,
				limit: 10,
				list: [],
				isLastPage: false,
				loading: false,
			}
		},
		onShow() {
			this.page = 1
			this.limit = 10
			this.list = []
			this.getScoreList()
		},
		// 刷新 上拉刷新
		onPullDownRefresh() {
			this.page = 1
			this.isLastPage = false
			this.list = []
			this.getScoreList().finally(() => {
				// 停止当前页面下拉刷新
				uni.stopPullDownRefresh();
			});
		},
		// 加载下一页 下拉加载
		onReachBottom() {
			if (this.list.length >= this.page * this.limit) {
				this.isLastPage = false;
				this.page += 1;
				this.getScoreList();
			} else {
				this.isLastPage = true
			}
		},
		methods: {
			chooseTabs(e) {
				this.list1Name = e.name
				this.status = e.status
				this.page = 1
				this.limit = 10
				this.list = []
				this.getScoreList()
			},
			// 列表
			async getScoreList() {
				this.$http.post(this.$api.course_list, {
					page: this.page,
					limit: this.limit,
					status: this.status
				}, {
					token: true
				}).then(res => {
					this.list = [...this.list, ...res.data]
				}).finally(() => {
					// 停止当前页面下拉刷新
					uni.stopPullDownRefresh();
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.writeOff {
		width: 100rpx;
		padding: 10rpx 20rpx;
		border-radius: 50rpx;
		background: #967C5E;
		font-size: 15px;
		color: #ffffff;
	}

	.class-item {
		display: flex;
		// align-items: center;
		border: 1rpx solid #967C5E;
		padding: 20rpx;
		border-radius: 20rpx;
		background-color: #FFFBF3;
		margin-bottom: 30rpx;
	}

	.goods-info-tag {
		padding: 5rpx 10rpx;
		font-weight: 400;
		font-size: 24rpx;
		color: #947065;
		background: rgba(148, 112, 101, 0.14);
		border-radius: 20rpx;
		border: 1rpx solid #967C5E;
		margin: 0 20rpx 20rpx 0;
	}
</style>